﻿using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using BankCreditPortfolio.DAL.Entities;

namespace BankCreditPortfolio.Models.ClientCabinetModels
{
    public class ChangeDetailsModel : IBaseModel<Profile>
    {
        [Required, StringLength(255, MinimumLength = 4)]
        [Display(Name = "Address")]
        public string Address { get; set; }

        [Required]
        [DataType(DataType.PhoneNumber)]
        [Display(Name = "Phone")]
        [RegularExpression(@"^ *\+[0-9]{5} [0-9]{7} *$", ErrorMessage = "The {0} is not in international format (+XXXXX XXXXXXX).")]
        public string Phone { get; set; }

        [Required, StringLength(255, MinimumLength = 4)]
        [Display(Name = "Workplace")]
        public string Workplace { get; set; }

        public IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
        {
            return new List<ValidationResult>();
        }

        public IBaseModel<Profile> MapFrom(Profile @from)
        {
            Address = from.Adress;
            Phone = from.Phone;
            Workplace = from.Work;
            return this;
        }

        public Profile MapTo(Profile to)
        {
            to.Adress = Address;
            to.Phone = Phone;
            to.Work = Workplace;
            return to;
        }
    }
}